package com.hbpu.encap.arrays;

import java.util.Scanner;

public class Homework02 {
    public static void main(String[] args) {
        System.out.println("请输入注册信息：");
        System.out.print("用户名：");
        String name = new Scanner(System.in).nextLine();
        System.out.print("密码：");
        String password = new Scanner(System.in).nextLine();
        System.out.print("邮箱：");
        String Email = new Scanner(System.in).nextLine();
        register(name, password, Email);
    }

    public static void register(String name, String password, String Email) {
        if (!(name.length() == 2 || name.length() == 3 || name.length() == 4)) {
            throw new RuntimeException("用户名长度不正确！");
        }
        if (!(password.length() == 6)) {
            throw new RuntimeException("密码长度必须为6");
        }

        try {
            int i = Integer.parseInt(password);
        } catch (NumberFormatException e) {
            throw new RuntimeException("密码必须为纯数字");
        }

        if (!(Email.contains("@") && Email.indexOf("@") < Email.indexOf("."))) {
            throw new RuntimeException("邮箱格式不正确");
        }

        System.out.println("注册成功！");
    }
}
